package com.wbb.result;

import com.wbb.constant.ResultConstants;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;

@Data
@NoArgsConstructor
@AllArgsConstructor
@Accessors(chain = true)
public class JsonResult<T> {
    private String code;
    private String message;
    private T data;

    public JsonResult(String code, String message) {
        this.code = code;
        this.message = message;
    }

    public static JsonResult ok(){
        return new JsonResult(ResultConstants.SUCCESS.getCode(), ResultConstants.SUCCESS.getMessage());
    }

    public static JsonResult fail(){
        return new JsonResult(ResultConstants.FAIL.getCode(), ResultConstants.FAIL.getMessage());
    }

    public static JsonResult response(ResultConstants resultConstants){
        return new JsonResult(resultConstants.getCode(),resultConstants.getMessage());
    }
}
